package edu.cmu.cs.cs214.hw9.client.controllers.eventhandlers;

import javax.swing.JFrame;

import edu.cmu.cs.cs214.hw9.client.controllers.FacelookController;
import edu.cmu.cs.cs214.hw9.client.gui.FacelookScreen;

/**
 * A generic event handler which provides subclasses with some utility functions.
 */
public abstract class EventHandler {
	protected FacelookController controller;
	
	protected EventHandler(FacelookController controller) {
		this.controller = controller;
	}
	
	/**
	 * Changes the panel/screen currently showing in the JFrame managed by the
	 * controller.
	 * 
	 * @param screen Screen to change to
	 */
	protected void changeScreen(FacelookScreen screen) {
		FacelookScreen view = controller.getView();
		JFrame frame = controller.getFrame();
		
		view.removeController(controller);
		screen.registerController(controller);
		
		frame.getContentPane().removeAll();
		frame.getContentPane().add(screen);
		frame.validate();
		frame.pack();
		frame.repaint();
	}
	
	/**
	 * Code to handle events.
	 * 
	 * @param param Event parameters
	 */
	public abstract void handleEvent(Object param);
}
